﻿using Ellanet.Annotations;
using Ellanet.Classes;
using Ellanet.Wrappers;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading;

namespace Ellanet.ViewModels
{
    class AnswersWindowViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private List<Sum> _sums;

        public List<Sum> Sums
        {
            get { return _sums; }
            set
            {
                _sums = value;
                OnPropertyChanged();
            }
        }

        public AnswersWindowViewModel(List<Sum> sums)
        {
            Sums = sums;
            ThreadPool.QueueUserWorkItem(SayAnswers);
        }

        private void SayAnswers(object stateInfo)
        {
            SpeechWrapper.Say("The answers in order are.", true);

            foreach (var sum in Sums)
            {
                SpeechWrapper.Say(sum.Answer.ToString(), true);
                //Thread.Sleep(50);
            }
        }

        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}